package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;
    //添加用户信息
    @ApiOperation("添加用户信息")
    @PostMapping("/addUser")
    public int AddUser(User user){
        System.out.println(user.getCreatetime());
        return userService.insertUser(user);
    }

    //删除用户信息
    @ApiOperation("删除用户信息")
    @GetMapping("/deleteUser")
    public int DeleteUser(int id){
        return userService.deleteUser(id);
    }

    //更新用户信息
    @ApiOperation("更新用户信息")
    @GetMapping("/updateUser")
    public int UpdateUser(User user) {
        return userService.updateUser(user);
    }

    //查看所有用户信息
    @ApiOperation("查看所有用户信息")
    @GetMapping("/selecteAllUser")
    public List<User>  SelectAllUser(){
        return userService.selectAllUser();
    }

    //查询指定用户
    @ApiOperation("查询指定用户")
    @GetMapping("/selectUser")
    public User selectUser(int id){
        return userService.selectUser(id);
    }

}
